//
//  SystemConfig.swift
//  CommonKit
//
//  Created by guohongqi on 2021/7/8.
//

import UIKit

public extension CGFloat{
    static let WJScreenWidth = UIScreen.main.bounds.size.width
    static let WJScreenHeight = UIScreen.main.bounds.size.height
    static let WJBottomAreaH:CGFloat = Bool.SCIsIPhoneX ? 34.0 : 0.0  // 底部安全区域
    static let WJStatusBarH:CGFloat = statusBarH()  // 顶部状态栏
    static let WJNavigationH:CGFloat = 44.0 + CGFloat.WJStatusBarH // 导航栏高度

}

public extension Bool{
    static var SCIsIPhoneX = (CGFloat.WJScreenHeight == 896 || CGFloat.WJScreenHeight == 812 || CGFloat.WJScreenHeight == 844 || CGFloat.WJScreenHeight == 926 )
    
}


@objc public extension UIApplication{

    @objc static func securyWindow() -> UIWindow?{
        if  #available(iOS 13.0, *) {
            for item in UIApplication.shared.connectedScenes where item is UIWindowScene {
                if item.activationState == .foregroundActive {
                    guard let windowScene = item as? UIWindowScene else {
                        return nil
                    }
                    for window in windowScene.windows {
                        if window.isKeyWindow {
                            return window
                        }
                    }
                    return nil
                }
            }
        }else{
            return UIApplication.shared.keyWindow
        }
        return UIApplication.shared.windows.last
    }
}


private func statusBarH() -> CGFloat {
    let statusBarHeight : CGFloat
    
    if #available(iOS 13, *) {
        statusBarHeight = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
    } else {
        statusBarHeight = UIApplication.shared.statusBarFrame.height
    }
    return statusBarHeight
}
